package com.sensetime.bi.senselink.server.rtsp.server.processor.localfile;

import com.sensetime.bi.senselink.server.entity.RtspRequestMsg;
import com.sensetime.bi.senselink.server.rtsp.server.processor.IRtspRequest;
import com.sensetime.bi.senselink.server.rtsp.server.processor.localfile.actions.DescribeAction;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import com.sensetime.bi.senselink.server.rtsp.server.processor.localfile.actions.OptionsAction;
import org.springframework.stereotype.Service;

@Slf4j
@Service(value = "RtspFileRequestProcessor")
public class RtspFileRequestProcessor implements IRtspRequest {
    @Override
    public void onOptionRequest(RtspRequestMsg request, Channel channel) {
        try {
            OptionsAction action = new OptionsAction(request);
            String optionResponse = action.call();

            log.debug("setup response header =====> \n" + optionResponse);
            channel.writeAndFlush(optionResponse);
            log.debug("write option response finish");
        } catch (Exception e) {
            log.error("Setup Request Handle Error.........", e);
        }
    }

    @Override
    public void onDescribeRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onDescribeRequest, channelId=" + channel.id());
        try {
            DescribeAction action = new DescribeAction(request);
            String describeResponse = action.call();

            log.debug("setup response header =====> \n" + describeResponse);
            channel.writeAndFlush(describeResponse);
            channel.flush();
            log.debug("write describe response finish");
        } catch (Exception e) {
            log.error("Setup Request Handle Error.........", e);
        }
    }

    @Override
    public void onSetupRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onDescribeRequest");
    }

    @Override
    public void onPlayRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onPlayRequest");
    }

    @Override
    public void onGetParameterRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onGetParameterRequest");
    }

    @Override
    public void onTeardownRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onTeardownRequest");
    }

    @Override
    public void onPauseRequest(RtspRequestMsg request, Channel channel) {
        log.info("process onPauseRequest");
    }
}
